package com.dhu.stylefit.controller;

import com.dhu.stylefit.Response;
import com.dhu.stylefit.dto.ClothesOneDTO;
import com.dhu.stylefit.service.ClothesOneService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/clothes-one")
@RequiredArgsConstructor
public class ClothesOneController {
    private final ClothesOneService clothesOneService;

    // 获取全部服装
    @GetMapping
    public Response<List<ClothesOneDTO>> getAllClothes() {
        try {
            List<ClothesOneDTO> data = (clothesOneService.getAllClothes());
            return Response.newSuccess(data);
        } catch (Exception e) {
            return Response.newFail("获取数据失败: " + e.getMessage());
        }
    }

    // 根据ID获取单个服装信息
    @GetMapping("/{id}")
    public Response<ClothesOneDTO> getClothesById(@PathVariable Integer id) {
        try {
            ClothesOneDTO data = clothesOneService.getClothesById(id);
            if (data != null) {
                return Response.newSuccess(data);
            } else {
                return Response.newFail("未找到ID为" + id + "的服装");
            }
        } catch (Exception e) {
            return Response.newFail("获取服装信息失败: " + e.getMessage());
        }
    }

}
